<?php
    require('inc/db.php');
    //评论
    if($_POST['name'] AND $_POST['email'] AND $_POST['message']){
        $sql="INSERT INTO comment (`post_id` ,`name` ,`email` ,`site`,`message` ,`times`)
        VALUES ('".$_GET['id']."', '".$_POST['name']."','".$_POST['email']."','".$_POST['site']."','".nl2br($_POST['message'])."',".time().")";
    mysql_query($sql);
    mysql_query("update post set comment_num = comment_num+1 where id = ".$_GET['id']);
    }
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        <?php
            $result = mysql_query("SELECT * FROM post WHERE id = ".$_GET['id']);
            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            echo $row['title'];
            }
            mysql_free_result($result);
        ?>
    </title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="topborder"></div>
<div id="header">
    <br/>
    <div id="logo"><?php require('inc/title.php');?></div>
    <p class="posted_at">
        <?php
         $result = mysql_query("SELECT * FROM post WHERE id = ".$_GET['id']." limit 1");
         $row = mysql_fetch_array($result, MYSQL_ASSOC);
         echo date('l F j Y',$row['post_time']);
         ?> 
    </p>
    <p class="author">
        yotomi @<a href="index.php" title="返回到首页">火星狐狸</a>，<a href="./list.php" title="返回到言论">言论</a>
        <?php echo '-'.$row['category'];?>
    </p>
</div>
<div id="contact">
<div class="post-content">
    <?php echo $row['content'];?>
    <br />
</div>
<h2>目前已有 <?php echo $row['comment_num']?> 评论</h2>
<?php
    // 显示评论
    $comment=mysql_query("SELECT * FROM comment WHERE post_id = ".$_GET['id']);
    while($row=mysql_fetch_array($comment,MYSQL_ASSOC)) {
        echo '<div class='.'"comment"'.'>';
        echo '<a href="http://'.$row['site'].'"'.'target="_blank"'.'>'.$row['name'].'</a>'.date(' H:i M jS D Y',$row['times']).'<br />'.'</div>';
        echo '<div class='.'"comment_meta"'.'>'.'<p>'.$row['message'].'</P>'.'</div>';
    }
    mysql_free_result($comment);
?>
<h2>发表评论：</h2>
<div id="comment">
    <form method="post" action="">
       <input type="hidden" name="pid" value="<?php echo $_GET['id']?>">
       <br /><input type="text" name="name" size="30">你的称呼<br />
       <br /><input type="text" name="email" size="30">你常用的邮箱<br />
       <br /><input type="text" name="site" size="30">你的主页或博客地址<br />
       <br /><textarea name="message" rows="6" cols="80"></textarea><br />
       <span class="submit">
            <input type="submit" value="好了，发表"/>
       </span>
    </form>
</div>
</div>
</div>
<div id="footer">
    <p>
        Copyright &copy; 2009-now yotomi . Here is <a href="http://yotomi.cn/blog">site</a> . </p>
    <p>
        <em style="font-size: 14px; font-style: normal;"></em>this is it</p>
</div>
</body>
</html>